from model.components.states.Ready import Ready
from model.components.states.Running import Running
from model.components.states.Terminated import Terminated
from model.components.states.WaitingIO import WaitingIO


class IrqHandler:
    def __init__(self, ready, memoryManager, scheduler, cpu):
        self.colaReady=ready
        self.memoryManager= memoryManager
        self.scheduler= scheduler
        self.cpu=cpu
        
    def timeOutHandler(self, pcb):
        pcb.status(Ready())
        self.memoryManager.free(pcb)
        pcb.remove(pcb)
        newPcb = self.scheduler.getPcb()
        newPcb.status(Running())
        self.cpu.setPCB(newPcb) 
        
    def killHandler(self, pcb):
        pcb.status(Terminated())
        self.memoryManager.free(pcb)
        pcb.remove(pcb)
        newPcb = self.scheduler.getPcb()
        self.cpu.setPCB(newPcb)     
    
    def ioHandler(self, pcb):
        pcb.status(WaitingIO ())
        newPcb = self.scheduler.getPcb()
        newPcb.status(Ready())
        self.cpu.setPCB(newPcb)
        
        
        